package com.example.hao.eventdistribution;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.TextView;

public class MyTextView extends android.support.v7.widget.AppCompatTextView {

    private static final String TAG = "MainActivity";

    public MyTextView(Context context) {
        super(context);
    }

    public MyTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * 事件分发
     *
     * @param event
     * @return true :表示终止整条事件链的传递; false:与 super.dispatchTouchEvent 效果一样,继续传递
     */
    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        Log.i(TAG, "dispatchTouchEvent: " + getTag());
//        switch (getTag().toString()) {
//            case "parent_child3_child2":
//                return false;
//        }
        return super.dispatchTouchEvent(event);
    }


    /**
     * 事件消费
     *
     * @param event
     * @return
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.i(TAG, "onTouchEvent: " + getTag());
//        switch (getTag().toString()) {
//            case "parent_child3_child2":
//
//                return true;
//        }
        return super.onTouchEvent(event);
    }

}
